/**
 * in formal language - regex language: A = aB, the "A","B" is NonTerminal
 * in outline, the language gramma is context free language
 * huizi 2024
 */
import {CONSTANTS} from '../common/consts.js';

/**
 * build termnal object
 * huizi 2024
 */
function nonTerminal(name, hasOwnScope = false, loopAble = false, isStart = false){
    const text = regex.replace("\\","");
    return {
        name: ()=> name,
        isStart: ()=> isStart,
        hasOwnScope: ()=> hasOwnScope,
        loopAble: ()=> loopAble,
        isList: ()=> (name.indexOf(CONSTANTS.END_WITH_LIST)===name.length-5) && name.length>5,
        isTerminal: ()=> false
    };
}

/**
 * all terminals in outline
 * huizi 2024
 */
const NonTerminals = ((...all)=>{
    /**
     * final result for non terminal enums
     */
    const result = {};

    /**
     * get the terminal from name
     */
    result.valueOf = name=>{
        if(name.endsWith("'")){
            return result.IGNORED;
        }else{
            return result[name.toUpperCase()];
        }
    };

    all.forEach(n=>{
        const [name, hasOwnScope, loopAble, isStart] = n;
        if(isStart===undefined) isStart = false;
        if(hasOwnScope===undefined) hasOwnScope = false;
        if(loopAble===undefined) loopAble = false;

        result[name] = nonTerminal(name, hasOwnScope, loopAble, isStart,);
    })

    return Object.freeze(result);

})(
    ["PROGRAM", true, false, true],
    ["NAMESPACE_DECLARE"],
    ["IMPORT_DECLARES"],
    ["IMPORT_DECLARE"],
    ["EXPORT_DECLARE"],
    ["COMMENT_STATEMENT"],
    ["STATEMENTS"],
    ["STATEMENT"],
    ["VAR_STATEMENT"],
    ["LET_STATEMENT"],
    ["ASSIGNMENT_STATEMENT"],
    ["EXPRESSION_STATEMENT"],
    ["VAR_ASSIGNMENT"],
    ["INITIAL_ASSIGNMENT"],
    ["NAMESPACE"],
    ["RETURN_STATEMENT"],
    ["ENTITY_BODY"],
    ["ARGUMENTS"],
    ["PIPE_FORWARD"],
    ["FUNC_CALL"],
    ["ENTITY_CALL"],
    ["ARRAY_ACCESS"],
    ["TUPLE_UNPACKER"],
    ["MATCH_BRANCH"],
    ["MATCH_VAR"],
    ["MATCH_WHEN"],
    ["MATCH_BLOCK"],
    ["MATCH_ELSE_BRANCH"],
    ["CONDITION_EXPRESSION"],
    ["LOOP_CONTROL"],
    ["RELATIONAL_CONDITION"],
    ["NEGATION"],
    ["EXPRESSION"],
    ["TERNARY_EXPRESSION"],
    ["NUMERIC_EXPRESSION"],
    ["TERM_EXPRESSION"],
    ["UNARY_EXPRESSION"],
    ["FACTOR_EXPRESSION"],
    ["IGNORED"],
    ["FUNC_DECLARE", true],
    ["ENTITY_DECLARE", true],
    ["ARRAY_DECLARE", true],
    ["MAP_DECLARE", true],
    ["MATCH_STATEMENT", true],
    ["EXTENSION_STATEMENT", true],
    ["IF_STATEMENT", true],
    ["TUPLE_DECLARE", true],
    ["IF_BRANCH", true],
    ["ELSE_STATEMENT", true],
    ["BLOCK_STATEMENT", true],
    ["DO_STATEMENT", true, true],
    ["WHILE_STATEMENT", true, true],
    ["EACH_STATEMENT", true, true],
    ["FOR_STATEMENT", true, true],
);

export {NonTerminals};
